#include <QNetworkRequest>
#include <QNetworkReply>

#include "netClient.h"

network::NetClient::NetClient(model::datacenter* dc)
    :dataCenter(dc)
{
}
network::NetClient::~NetClient()
{}

void network::NetClient::ping()
{
    QNetworkRequest httpReq;
    httpReq.setUrl(HTTP_URL + "/ping");

    QNetworkReply* httpResp = httpClient.get(httpReq);
    connect(httpResp,&QNetworkReply::finished,this,[=](){
        // 这里面, 说明响应已经回来了
        if(httpResp->error() != QNetworkReply::NoError)
        {
            // 请求失败！
            LOG_ERROR << "Http请求失败！" << httpResp->errorString();
            httpResp->deleteLater();
            return;
        }

        // 获取到响应的 body
        QByteArray body = httpResp->readAll();
        LOG_DEBUG << "响应内容：" << body;
        httpResp->deleteLater();
    });
}


